@extends('layouts.layout')

@section('content')

    {{--图片上传--}}
    <script src="{{asset('upload/js/vendor/jquery.ui.widget.js')}}"></script>
    <script src="{{asset('upload/js/jquery.iframe-transport.js')}}"></script>
    <script src="{{asset('upload/js/jquery.fileupload.js')}}"></script>
    <script src="{{asset('upload/js/uploadImg.js')}}"></script>
    {{--/图片上传--}}

    <div class="header">
        @include('layouts.count')

        <h1 class="page-title">文章管理</h1>
        <ul class="breadcrumb">
            <li  class="active">文章列表 </li>
            <li class="active">文章编辑</li>
        </ul>

    </div>




    <ul class="nav nav-tabs">
        <li class="active"><a href="#home" data-toggle="tab">Profile</a></li>
        {{--<li class=""><a href="#profile" data-toggle="tab">Password</a></li>--}}
    </ul>

    <div class="row">
        <div class="col-md-8">
            <br>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane active" id="home">
                    <form id="tab" action="{{url('article/'.$article->id)}}" method="post">
                        {{csrf_field()}}
                        <input type="hidden" name="_method" value="put">
                        <div class="form-group">
                            <label>文章类别</label>
                            <select name="category" id="DropDownTimezone" class="form-control">
                                @if($common_arr['super_id']==1)
                                <option value="1" @if($article->category=='1') selected @endif>新闻资讯</option>
                                <option value="2" @if($article->category=='2') selected @endif>公告</option>
                                <option value="3" @if($article->category=='3') selected @endif>重要信息</option>
                                <option value="4" @if($article->category=='4') selected @endif>人才政策</option>
                                <option value="5" @if($article->category=='5') selected @endif>产业政策</option>
                                    @elseif($common_arr['super_id']!=1)
                                    <option value="1" @if($article->category=='1') selected @endif>新闻资讯</option>
                                    @endif
                            </select>
                            <input type="hidden" name="category" value="{{$article->category}}" id="category">
                        </div>



                        <div class="form-group">
                            <label>标题*</label>
                            <input type="text" value="{{$article->title}}" class="form-control" name="title">
                        </div>



                        <div class="form-group">
                            <label>描述</label></br>
                            <textarea name="desc" style="width: 100% ; height: 80px">{{$article->desc}} </textarea>
                        </div>


                        <div class="form-group">
                            <label>上传图片*</label></br>

                            <input class="form-control" id="field-1" type="file" onclick="fileupload($(this),$(this).closest('div'),'avatar',1,'fileuplade');" name="file" data-url="{{url('admin/upload')}}">
                            <div class="progress">
                                <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                                </div>
                            </div>
                            <input type="hidden" id="table" value="cms_articles" />
                            <input type="hidden" id="key1" value="{{$article->id}}" />
                            <input type="hidden" id="key2" value="avatar" />
                            <section class="gallery-env">
                                <div class="row">
                                    <!-- Gallery Album Optipns and Images -->
                                    <div class="col-sm-12">
                                        <!-- Album Images -->
                                        <div class="album-images row" id="fileuplade">
                                            <!-- Album Image -->
                                            @if($article->avatar!='')
                                            <div class="col-md-4 col-sm-12 col-xs-6 list-img" >
                                                <div class="album-image"><input type="hidden" name="avatar" value="{{asset($article->avatar)}}">

                                                    <a href="javascript:;" onclick="lookImg('{{asset($article->avatar)}}')" class="thumb" data-action="edit" style="height: 120px;overflow: hidden;">


                                                        <img src="{{asset($article->avatar)}}" class="img-responsive"></a>


                                                    <div class="image-options"><a title="删除" href="javascript:;" class="deleteTheImg" data-action="trash" data-url="{{$article->avatar}}"><i class="fa fa-trash-o"></i></a>

                                                    </div>

                                                    <div>

                                                        <div>


                                                        </div>

                                                    </div>

                                                </div>
                                            </div>
                                                @endif


                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>

                        <div class="form-group">
                            <label>内容</label>

                            @include('UEditor::head')
                            <script id="ueditor" name="content" type="text/plain" style="width: 100%; height:300px">{!!$article->content!!} </script>

                            </div>
                        </div>





                            {{--<div class="form-group">--}}
                            {{--<label>Time Zone</label>--}}
                            {{--<select name="DropDownTimezone" id="DropDownTimezone" class="form-control">--}}
                            {{--<option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>--}}
                            {{--</select>--}}
                            {{--</div>--}}
                            </form>
                         </div>

                            {{--<div class="tab-pane" id="profile">--}}

                            {{--<form id="tab2">--}}
                            {{--<div class="form-group">--}}
                            {{--<label>New Password</label>--}}
                            {{--<input type="password" class="form-control">--}}
                            {{--</div>--}}
                            {{--<div>--}}
                            {{--<button class="btn btn-primary">Update</button>--}}
                            {{--</div>--}}
                            {{--</form>--}}
                            {{--</div>--}}
                            {{--</div>--}}

                            <div class="btn-toolbar list-toolbar">
                                <button class="btn btn-primary" id="btn"><i class="fa fa-save"></i> Save</button>
                                    {{--<a href="#myModal" data-toggle="modal" class="btn btn-danger">Delete</a>--}}
                                </div>
                          </div>
                     </div>

                                <div class="modal small fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                <div class="modal-content">
                                <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h3 id="myModalLabel">Delete Confirmation</h3>
                            </div>
                            <div class="modal-body">

                                <p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?</p>
                            </div>
                            <div class="modal-footer">
                                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
                                <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                                </div>
                                </div>
                                </div>
                                </div>




</div>



                                <script type="text/javascript">
                            var ue=UE.getEditor("ueditor");
                            ue.ready(function(){
                                //因为Laravel有防csrf防伪造攻击的处理所以加上此行
                                ue.execCommand('serverparam','_token','{{ csrf_token() }}');
                            });
                            </script>


                            <script type="text/javascript">






                                $("#btn").click(function(){    // 提交按钮触发事件

                                    var tourl = $("#tab").attr("action");    // 获取 表单的 提交地址
                                    // 序列化 表单数据 后提交 ，太简洁了
                                    $.post(tourl,$("#tab").serialize(),function(data){


                                        //直接返回首页
                                        /*layer.msg(data['info'],5,data['status'],function(){
                                            location.href = "{:U('Index/index')}"; //自动关闭后返回首页
                                        });*/
                                        //确定返回首页还是再次添加


                                        if(data.status_code==200){
                                            //询问框
                                            layer.confirm(data.msg, {
                                                btn: ['返回首页','继续修改'] //按钮
                                            }, function(){
                                                location.href = "{{url('article')}}";
//                                                layer.msg('的确很重要', {icon: 1});
                                            }, function(){
                                                location.reload();
//                                                layer.msg('也可以这样', {
//                                                    time: 20000, //20s后自动关闭
//                                                    btn: ['明白了', '知道了']
//                                                });
                                            });
                                        }else{
                                            layer.msg(data.msg,{icon:5},function(){
                                                time:1000;
                                            })
                                        }

                                    });
                                });

                                /**
                                 * seletor 赋值函数
                                 */

                                $('#DropDownTimezone').change(function(){
                                    $('#category').val($(this).val());
                                });


                            </script>


@endsection